package com.hmall.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hmall.api.controller.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import com.hmall.order.domain.po.OrderDetail;
import com.hmall.order.mapper.OrderDetailMapper;
import com.hmall.order.service.IOrderDetailService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单详情表 服务实现类
 * </p>
 *
 * @author 虎哥
 * @since 2023-05-05
 */
@Service
@AllArgsConstructor
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {


    @Override
    public List<OrderDetailDTO> getItemByOrderId(Long id) {
        List<OrderDetail> orderDetailList = lambdaQuery().eq(OrderDetail::getOrderId, id).list();
        List<OrderDetailDTO> resultList=new ArrayList<>();
        for (OrderDetail detail : orderDetailList) {
            OrderDetailDTO detailDTO=new OrderDetailDTO(detail.getItemId(),detail.getNum());
            resultList.add(detailDTO);
        }

        return resultList;
    }
}
